package com.whcoding.async.service.impl;

import com.whcoding.async.service.AsyncService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @program: spring-boot-learning
 * @description:
 * @author: whcoding
 * @create: 2022-02-24 14:49
 **/

@Service
public class AsyncServiceImpl implements AsyncService {
	/**
	 * 告诉spring 这个是一个异步方法
	 */
	@Override
	public void syncHelloTask() {
		try {
			Thread.sleep(3000);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("数据正在处理中");
	}

	/**
	 * 告诉spring 这个是一个异步方法 调用不用等待就会执行
	 */
	@Async
	@Override
	public void asyncHelloTaskSleep() {
		try {
			Thread.sleep(5000);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("数据正在处理中，异步执行");
	}
}